package yxy.cherry.battle.module.selector;

import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.Team;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Set;

@TargetSelectorType(Type = 25)
public class TargetSelector_25_血量排序 extends TargetSelector {

	@Override
	public Set<Fighter> target(Fighter actor, Team team, int param1, int param2) {
		ArrayList<Fighter> list = sort血量(team);

		return getSpecialFighter(actor,list,param1,param2);
	}

	private ArrayList<Fighter> sort血量(Team team) {
		ArrayList<Fighter> list = new ArrayList<>();
		for (Fighter fighter : team.getFighters()) {
			if (fighter.is活着()) {
				list.add(fighter);
			}
		}

		list.sort(new Comparator<Fighter>() {

			@Override
			public int compare(Fighter o1, Fighter o2) {

				if (!o1.is活着()) {
					return -1;
				}
				int value = o1.get血量() > o2.get血量() ? 1 : -1;
				if (o1.get血量() == o2.get血量()) {
					value = o2.get血量() > o1.get血量() ? 1 : -1;
					return value;
				}
				return value;
			}
		});
		return list;
	}
}